package com.firewolf.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import com.firewolf.entities.User;

public class UserDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public User findByUsername(String username) {
		List<User> userList = null;
		try {
			String sql = "select id, username, password, salt, locked from sys_users where username=?";
			userList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(User.class), username);
			if (userList.size() == 0) {
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return userList.get(0);
	}

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
}
